package com.sl.au.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.AfterSaleTicket;
import com.sl.au.entity.Contract;
import com.sl.au.entity.ContractInfoView;
import com.sl.au.entity.ExdeContractPrudctP;
import com.sl.au.entity.Option;

@Transactional(readOnly = true)
public interface ExdeContractViewRepository extends JpaRepository<ContractInfoView, String> {

	@Query("select c.superior from SaleArea c group by c.superior ")
	List<Option> getSaleArea();
	
	//String nameDate, Date startDate, Date endDate, Double totalSum, String superior, String orderArea, String dutyOfficer, String industryInfo, String generateState, String contractState, String state, String contractType
	//创建时间
	@Query("select c from ContractInfoView c where c.createTime=?2 and c.createTime<=?3 and c.totalSum=?3  ")
	List<ContractInfoView> getContractInfos(Date startDate, Date endDate, Double totalSum);
	
	@Query("select Count(*) from ContractInfoView c where c.createTime>=?2 and c.createTime<=?3 and c.totalSum=?3 ")
	long getContractInfosCount(Date startDate, Date endDate, Double totalSum);
	
	@Query("select c from ContractInfoView c where c.id in "
			+ "( select dr.detailContractID from DetailRelevance dr where dr.contractID=?1 and dr.detailContractType=?2 ) ")
	List<ContractInfoView> getBeiViewById(String contractViewId, String contractViewType, Pageable pageable);
	@Query("select Count(*) from ContractInfoView c where c.id in "
			+ "( select dr.detailContractID from DetailRelevance dr where dr.contractID=?1 and dr.detailContractType=?2 ) ")
	long getBeijianViewCount(String contractViewId, String contractViewType);

	@Query("select a from AfterSaleTicket a where a.contractId=?1 ")
	List<AfterSaleTicket> getAfterSaleTicket(String contractViewId, Pageable pageable);
	
	@Query("select count(*) from AfterSaleTicket a where a.contractId=?1 ")
	long getAfterSaleTicketCount(String contractViewId);
	
	@Query("select c from ExdeContractPrudctP c where c.contractNumber=?1 ")
	List<ExdeContractPrudctP> getSpeed(String supplierCode);
}
